

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>geoslurp.db.settings &mdash; geoslurp v1.1.0 documentation</title>
  

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../../../genindex.html"/>
        <link rel="search" title="Search" href="../../../search.html"/>
    <link rel="top" title="geoslurp v1.1.0 documentation" href="../../../index.html"/>
        <link rel="up" title="Module code" href="../../index.html"/> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> geoslurp
          

          
          </a>

          
            
            
              <div class="version">
                1.1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../introduction.html">An introduction to Geoslurp</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../installation.html">Installation of the geoslurp package and setting up the PostgreSQL instance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../confsettings.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../examples.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../reference.html">Reference Documentation</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">geoslurp</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>geoslurp.db.settings</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for geoslurp.db.settings</h1><div class="highlight"><pre>
<span></span><span class="c1"># This file is part of geoslurp.</span>
<span class="c1"># geoslurp is free software; you can redistribute it and/or</span>
<span class="c1"># modify it under the terms of the GNU Lesser General Public</span>
<span class="c1"># License as published by the Free Software Foundation; either</span>
<span class="c1"># version 3 of the License, or (at your option) any later version.</span>

<span class="c1"># geoslurp is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<span class="c1"># Lesser General Public License for more details.</span>

<span class="c1"># You should have received a copy of the GNU Lesser General Public</span>
<span class="c1"># License along with Frommle; if not, write to the Free Software</span>
<span class="c1"># Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>

<span class="c1"># Author Roelof Rietbroek (roelof@geod.uni-bonn.de), 2018</span>

<span class="c1"># reads and writes contains a class to work with  the geoslurp inventory table</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">Column</span><span class="p">,</span><span class="n">Integer</span><span class="p">,</span><span class="n">String</span><span class="p">,</span><span class="n">Float</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.ext.declarative</span> <span class="k">import</span> <span class="n">declarative_base</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.dialects.postgresql</span> <span class="k">import</span> <span class="n">JSONB</span><span class="p">,</span> <span class="n">BYTEA</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.ext.mutable</span> <span class="k">import</span> <span class="n">MutableDict</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">MetaData</span>

<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="k">import</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">geoslurp.config.slurplogger</span> <span class="k">import</span> <span class="n">slurplogger</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">cryptography.hazmat.primitives.ciphers</span> <span class="k">import</span> <span class="n">Cipher</span><span class="p">,</span> <span class="n">algorithms</span><span class="p">,</span> <span class="n">modes</span>
<span class="kn">from</span> <span class="nn">cryptography.hazmat.backends</span> <span class="k">import</span> <span class="n">default_backend</span>



<div class="viewcode-block" id="MirrorMap"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.MirrorMap">[docs]</a><span class="k">class</span> <span class="nc">MirrorMap</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">from_mirror</span><span class="p">,</span><span class="n">to_mirror</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">from_mirror</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">to_mirror</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;The url of the data mirrors used for mapping should end with a &#39;/&#39;&quot;</span><span class="p">)</span> 
        <span class="bp">self</span><span class="o">.</span><span class="n">from_mirror</span><span class="o">=</span><span class="n">from_mirror</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">to_mirror</span><span class="o">=</span><span class="n">to_mirror</span>
<div class="viewcode-block" id="MirrorMap.apply"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.MirrorMap.apply">[docs]</a>    <span class="k">def</span> <span class="nf">apply</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">url</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">url</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">from_mirror</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">to_mirror</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="MirrorMap.reverseApply"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.MirrorMap.reverseApply">[docs]</a>    <span class="k">def</span> <span class="nf">reverseApply</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">url</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">url</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">to_mirror</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">from_mirror</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="MirrorMap.strip"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.MirrorMap.strip">[docs]</a>    <span class="k">def</span> <span class="nf">strip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">url</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">url</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">from_mirror</span><span class="p">,</span><span class="s2">&quot;&quot;</span><span class="p">)</span></div></div>

<div class="viewcode-block" id="getCreateDir"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.getCreateDir">[docs]</a><span class="k">def</span> <span class="nf">getCreateDir</span><span class="p">(</span><span class="n">returndir</span><span class="p">,</span><span class="n">mirrormapper</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;creates a directory when not existent and return it</span>
<span class="sd">    When a mirrormapper is specified the base is converted&quot;&quot;&quot;</span>

    <span class="c1">#possibly expand environment variables in the string</span>
    <span class="n">returnex</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expandvars</span><span class="p">(</span><span class="n">returndir</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">mirrormapper</span><span class="p">:</span>
        <span class="n">returnex</span><span class="o">=</span><span class="n">mirrormapper</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">returnex</span><span class="p">)</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">returnex</span><span class="p">):</span>
        <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">returnex</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">returnex</span></div>

<div class="viewcode-block" id="stripPasswords"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.stripPasswords">[docs]</a><span class="k">def</span> <span class="nf">stripPasswords</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">serv</span><span class="p">,</span><span class="n">dsub</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="c1"># print(serv)</span>
        <span class="k">for</span> <span class="n">ky</span><span class="p">,</span><span class="n">v</span> <span class="ow">in</span> <span class="n">dsub</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">ky</span> <span class="o">==</span> <span class="s2">&quot;passw&quot;</span> <span class="ow">or</span> <span class="n">ky</span> <span class="o">==</span> <span class="s2">&quot;oauth&quot;</span><span class="p">:</span>
                <span class="n">d</span><span class="p">[</span><span class="n">serv</span><span class="p">][</span><span class="n">ky</span><span class="p">]</span><span class="o">=</span><span class="s2">&quot;*****&quot;</span>
    <span class="k">return</span> <span class="n">d</span></div>

<span class="n">Credentials</span><span class="o">=</span><span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;Credentials&quot;</span><span class="p">,</span><span class="s2">&quot;user passw alias oauthtoken url&quot;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;A named tuple to store authentication credentials</span>

<span class="sd">Attributes:</span>
<span class="sd">    user (str): Username for the service</span>
<span class="sd">    alias (str): (obligatory) The short name of this service</span>
<span class="sd">    passw (str): The password associated with the username</span>
<span class="sd">    oauthtoken (str): An oauth2 token</span>
<span class="sd">    url (str): The root url which is linked to this service</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">Credentials</span><span class="o">.</span><span class="fm">__new__</span><span class="o">.</span><span class="vm">__defaults__</span> <span class="o">=</span> <span class="p">(</span><span class="kc">None</span><span class="p">,)</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">Credentials</span><span class="o">.</span><span class="n">_fields</span><span class="p">)</span>

<span class="n">GSBase</span><span class="o">=</span><span class="n">declarative_base</span><span class="p">(</span><span class="n">metadata</span><span class="o">=</span><span class="n">MetaData</span><span class="p">(</span><span class="n">schema</span><span class="o">=</span><span class="s1">&#39;admin&#39;</span><span class="p">))</span>


<div class="viewcode-block" id="SettingsTable"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.SettingsTable">[docs]</a><span class="k">class</span> <span class="nc">SettingsTable</span><span class="p">(</span><span class="n">GSBase</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Defines the GEOSLURP POSTGRESQL settings table&quot;&quot;&quot;</span>
    <span class="n">__tablename__</span><span class="o">=</span><span class="s1">&#39;settings&#39;</span>
    <span class="nb">id</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">user</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">String</span><span class="p">,</span> <span class="n">unique</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">conf</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">MutableDict</span><span class="o">.</span><span class="n">as_mutable</span><span class="p">(</span><span class="n">JSONB</span><span class="p">))</span>
    <span class="n">auth</span><span class="o">=</span><span class="n">Column</span><span class="p">(</span><span class="n">BYTEA</span><span class="p">)</span> <span class="c1"># stored as blowfish encrypted bytearray</span></div>


<div class="viewcode-block" id="Settings"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings">[docs]</a><span class="k">class</span> <span class="nc">Settings</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Read and write default and user specific settings to and from the database&quot;&quot;&quot;</span>
    <span class="n">table</span><span class="o">=</span><span class="n">SettingsTable</span>
    <span class="n">mirrorMap</span><span class="o">=</span><span class="kc">None</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">dbconn</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">=</span><span class="n">dbconn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
        <span class="c1">#creates the settings table if it doesn&#39;t exists</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">has_table</span><span class="p">(</span><span class="s1">&#39;settings&#39;</span><span class="p">,</span><span class="n">schema</span><span class="o">=</span><span class="s1">&#39;admin&#39;</span><span class="p">):</span>
            <span class="n">GSBase</span><span class="o">.</span><span class="n">metadata</span><span class="o">.</span><span class="n">create_all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dbeng</span><span class="p">)</span>
            <span class="c1"># #also grant geoslurp all privileges</span>
            <span class="c1"># #geoslurp users need to be able to add themselves to the admin.settings table</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">&#39;GRANT ALL PRIVILEGES ON admin.settings to geoslurp&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">&#39;GRANT USAGE ON SEQUENCE admin.settings_id_seq to geoslurp&#39;</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="c1">#extract the default entry</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">user</span> <span class="o">==</span> <span class="s1">&#39;default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">one</span><span class="p">()</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c1">#create a new default entry</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">=</span><span class="n">SettingsTable</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">,</span><span class="n">conf</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;CacheDir&quot;</span><span class="p">:</span><span class="s2">&quot;/tmp&quot;</span><span class="p">,</span><span class="s2">&quot;MirrorMaps&quot;</span><span class="p">:{</span><span class="s2">&quot;default&quot;</span><span class="p">:</span><span class="s2">&quot;$</span><span class="si">{HOME}</span><span class="s2">/geoslurpdata&quot;</span><span class="p">}})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
            <span class="c1">#also create a view to the default which may be read by the geobrowse group</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">dbeng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;CREATE VIEW admin.settings_</span><span class="si">%s</span><span class="s2">efault as select * from admin.settings as t where t.user  = &#39;default&#39;&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">eng</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s2">&quot;GRANT SELECT ON admin.settings_default to geobrowse&quot;</span><span class="p">)</span>


            <span class="c1">#retrieve again</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">user</span> <span class="o">==</span> <span class="s1">&#39;default&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">one</span><span class="p">()</span>
        <span class="c1">#retrieve/create a user entry</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="o">.</span><span class="n">user</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="p">)</span><span class="o">.</span><span class="n">one</span><span class="p">()</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="o">=</span><span class="p">{}</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c1">#make a new empty entry</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="p">,</span><span class="n">conf</span><span class="o">=</span><span class="p">{})</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">decryptAuth</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">dbconn</span><span class="o">.</span><span class="n">mirror</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">dbconn</span><span class="o">.</span><span class="n">mirror</span> <span class="o">!=</span> <span class="s2">&quot;default&quot;</span><span class="p">:</span>
                <span class="c1">#we need to apply a mapping of the directory names for this instance</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">mirrorMap</span><span class="o">=</span><span class="n">MirrorMap</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">getMirror</span><span class="p">(</span><span class="n">dbconn</span><span class="o">.</span><span class="n">mirror</span><span class="p">),</span><span class="bp">self</span><span class="o">.</span><span class="n">getMirror</span><span class="p">(</span><span class="s2">&quot;default&quot;</span><span class="p">))</span>
        <span class="k">elif</span> <span class="s2">&quot;MirrorMaps&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
            <span class="c1">#automatically try to figure out whether a mapping is needed by checking the existence of directories</span>
            <span class="k">for</span> <span class="n">alias</span><span class="p">,</span><span class="n">pth</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="s2">&quot;MirrorMaps&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">pth</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">mirrorMap</span><span class="o">=</span><span class="n">MirrorMap</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">getMirror</span><span class="p">(</span><span class="s2">&quot;default&quot;</span><span class="p">),</span><span class="n">pth</span><span class="p">)</span>
                    <span class="k">break</span>
        <span class="c1"># self.loaduserplugins()</span>

    <span class="c1">#The operators below overload the [] operators allowing the retrieval and  setting of dictionary items</span>
    <span class="k">def</span> <span class="nf">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
            <span class="c1">#try finding the key in the defaults</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Cannot find setting in user configuration or defaults&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__setitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">=</span><span class="n">val</span>

    <span class="k">def</span> <span class="nf">__delitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
    
<div class="viewcode-block" id="Settings.getdefaults"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.getdefaults">[docs]</a>    <span class="k">def</span> <span class="nf">getdefaults</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">key</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;returns the default&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span></div>

<div class="viewcode-block" id="Settings.setdefault"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.setdefault">[docs]</a>    <span class="k">def</span> <span class="nf">setdefault</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">key</span><span class="p">,</span><span class="n">val</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">=</span><span class="n">val</span></div>

<div class="viewcode-block" id="Settings.show"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.show">[docs]</a>    <span class="k">def</span> <span class="nf">show</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Show the loaded user configuration&quot;&quot;&quot;</span>
        <span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">)</span>
        <span class="c1">#also shows the registered authentification services (but don&#39;t show passwords</span>
        <span class="nb">print</span><span class="p">(</span><span class="n">stripPasswords</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">))</span></div>

<div class="viewcode-block" id="Settings.authCred"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.authCred">[docs]</a>    <span class="k">def</span> <span class="nf">authCred</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">service</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;obtains username credentials for a certain service</span>
<span class="sd">        :param service: name of the service</span>
<span class="sd">        :returns a namedtuple with credentials&quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">service</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;No credentials for service </span><span class="si">%s</span><span class="s2"> found in the database. Please register your credentials using Settings.updateAuth()&quot;</span><span class="o">%</span><span class="n">service</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">Credentials</span><span class="p">(</span><span class="n">alias</span><span class="o">=</span><span class="n">service</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">[</span><span class="n">service</span><span class="p">])</span></div>

<div class="viewcode-block" id="Settings.updateAuth"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.updateAuth">[docs]</a>    <span class="k">def</span> <span class="nf">updateAuth</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cred</span><span class="p">:</span><span class="n">Credentials</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;register/update a new set of authentication credentials&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">cred</span><span class="o">.</span><span class="n">alias</span><span class="p">:</span><span class="nb">dict</span><span class="p">([(</span><span class="n">ky</span><span class="p">,</span> <span class="n">val</span><span class="p">)</span> <span class="k">for</span> <span class="n">ky</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">cred</span><span class="o">.</span><span class="n">_fields</span><span class="p">,</span> <span class="n">cred</span><span class="p">)</span> <span class="k">if</span> <span class="nb">bool</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> <span class="ow">and</span> <span class="n">ky</span> <span class="o">!=</span> <span class="s2">&quot;alias&quot;</span><span class="p">])})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encryptAuth</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span></div>

<div class="viewcode-block" id="Settings.delAuth"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.delAuth">[docs]</a>    <span class="k">def</span> <span class="nf">delAuth</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">key</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Delete an authentication entry by specifying it&#39;s alias&quot;&quot;&quot;</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encryptAuth</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span></div>

<div class="viewcode-block" id="Settings.update"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">indict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update the conf dictionary in postgresql settings table&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">indict</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
                <span class="c1"># check for none values and delete those entries</span>
                <span class="k">for</span> <span class="n">ky</span><span class="p">,</span><span class="n">val</span> <span class="ow">in</span> <span class="n">indict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">val</span> <span class="o">==</span> <span class="s1">&#39;None&#39;</span><span class="p">:</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">ky</span><span class="p">]</span>
                        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                            <span class="n">slurplogger</span><span class="p">()</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Cannot find key: </span><span class="si">%s</span><span class="s2"> in user configuration, ignoring..&quot;</span><span class="o">%</span><span class="p">(</span><span class="n">ky</span><span class="p">))</span>
                            <span class="k">pass</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="n">ky</span><span class="p">]</span><span class="o">=</span><span class="n">val</span>

                <span class="c1"># self.userentry.conf.update(indict)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">conf</span><span class="o">=</span><span class="n">indict</span>


        <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span></div>
    
<div class="viewcode-block" id="Settings.defaultupdate"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.defaultupdate">[docs]</a>    <span class="k">def</span> <span class="nf">defaultupdate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">indict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update the default conf dictionary in postgresql settings table&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">indict</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">indict</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="o">=</span><span class="n">indict</span>


        <span class="bp">self</span><span class="o">.</span><span class="n">ses</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span></div>
    
<div class="viewcode-block" id="Settings.getMirror"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.getMirror">[docs]</a>    <span class="k">def</span> <span class="nf">getMirror</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">alias</span><span class="p">):</span>
        <span class="k">if</span> <span class="s2">&quot;MirrorMaps&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="s2">&quot;MirrorMaps&quot;</span><span class="p">][</span><span class="n">alias</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defaultentry</span><span class="o">.</span><span class="n">conf</span><span class="p">[</span><span class="s2">&quot;DataDir&quot;</span><span class="p">]</span></div>

<div class="viewcode-block" id="Settings.setMirror"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.setMirror">[docs]</a>    <span class="k">def</span> <span class="nf">setMirror</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">alias</span><span class="p">,</span><span class="n">mirror</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">defaultupdate</span><span class="p">({</span><span class="s2">&quot;MirrorMaps&quot;</span><span class="p">:{</span><span class="n">alias</span><span class="p">:</span><span class="n">mirror</span><span class="p">}})</span></div>

<div class="viewcode-block" id="Settings.encryptAuth"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.encryptAuth">[docs]</a>    <span class="k">def</span> <span class="nf">encryptAuth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Encrypt the authentification credentials to store in the database&quot;&quot;&quot;</span>
        <span class="n">bs</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">algorithms</span><span class="o">.</span><span class="n">Blowfish</span><span class="o">.</span><span class="n">block_size</span> <span class="o">/</span> <span class="mi">8</span><span class="p">)</span>
        <span class="n">backend</span> <span class="o">=</span> <span class="n">default_backend</span><span class="p">()</span>
        <span class="n">iv</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">urandom</span><span class="p">(</span><span class="n">bs</span><span class="p">)</span>
        <span class="n">cipher</span> <span class="o">=</span> <span class="n">Cipher</span><span class="p">(</span><span class="n">algorithms</span><span class="o">.</span><span class="n">Blowfish</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">passw</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)),</span> <span class="n">modes</span><span class="o">.</span><span class="n">CBC</span><span class="p">(</span><span class="n">iv</span><span class="p">),</span> <span class="n">backend</span><span class="o">=</span><span class="n">backend</span><span class="p">)</span>
        <span class="n">encryptor</span> <span class="o">=</span> <span class="n">cipher</span><span class="o">.</span><span class="n">encryptor</span><span class="p">()</span>
        <span class="n">conf</span><span class="o">=</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span>
        <span class="c1">#padd with spaces to be a multiple of bs</span>
        <span class="n">plen</span> <span class="o">=</span> <span class="n">bs</span> <span class="o">-</span> <span class="nb">divmod</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">conf</span><span class="p">),</span> <span class="n">bs</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">pad</span> <span class="o">=</span> <span class="sa">b</span><span class="s1">&#39; &#39;</span><span class="o">*</span><span class="n">plen</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="n">iv</span> <span class="o">+</span> <span class="n">encryptor</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">conf</span><span class="o">+</span><span class="n">pad</span><span class="p">)</span> <span class="o">+</span> <span class="n">encryptor</span><span class="o">.</span><span class="n">finalize</span><span class="p">()</span></div>
        <span class="c1"># bs = Blowfish.block_size</span>
        <span class="c1"># iv=Random.new().read(bs)</span>
        <span class="c1"># crypto = Blowfish.new(self.db.passw, Blowfish.MODE_CBC, iv)</span>
        <span class="c1"># conf=json.dumps(self.auth)</span>
        <span class="c1"># #padd with spaces to be a multiple of bs</span>
        <span class="c1"># plen = bs - divmod(len(conf), bs)[1]</span>
        <span class="c1"># pad = &#39; &#39;*plen</span>
        <span class="c1"># self.userentry.auth = iv + crypto.encrypt(conf + pad)</span>
        <span class="c1">#</span>

<div class="viewcode-block" id="Settings.decryptAuth"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.decryptAuth">[docs]</a>    <span class="k">def</span> <span class="nf">decryptAuth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Decrypt the authenficiation credentials as stored in the database&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">auth</span><span class="p">:</span>
            <span class="n">bs</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">algorithms</span><span class="o">.</span><span class="n">Blowfish</span><span class="o">.</span><span class="n">block_size</span><span class="o">/</span><span class="mi">8</span><span class="p">)</span>
            <span class="n">backend</span> <span class="o">=</span> <span class="n">default_backend</span><span class="p">()</span>
            <span class="n">iv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">auth</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">bs</span><span class="p">]</span>
            <span class="n">encr</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">userentry</span><span class="o">.</span><span class="n">auth</span><span class="p">[</span><span class="n">bs</span><span class="p">:]</span>
            <span class="n">cipher</span> <span class="o">=</span> <span class="n">Cipher</span><span class="p">(</span><span class="n">algorithms</span><span class="o">.</span><span class="n">Blowfish</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">passw</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)),</span> <span class="n">modes</span><span class="o">.</span><span class="n">CBC</span><span class="p">(</span><span class="n">iv</span><span class="p">),</span> <span class="n">backend</span><span class="o">=</span><span class="n">backend</span><span class="p">)</span>
            <span class="n">decryptor</span> <span class="o">=</span> <span class="n">cipher</span><span class="o">.</span><span class="n">decryptor</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="o">=</span><span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">decryptor</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">encr</span><span class="p">)</span> <span class="o">+</span> <span class="n">decryptor</span><span class="o">.</span><span class="n">finalize</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">auth</span><span class="o">=</span><span class="p">{}</span></div>

        <span class="c1"># bs = Blowfish.block_size</span>
        <span class="c1"># if self.userentry.auth:</span>
        <span class="c1">#     entry=self.userentry.auth</span>
        <span class="c1">#     iv=self.userentry.auth[0:bs]</span>
        <span class="c1">#     encr=self.userentry.auth[bs:]</span>
        <span class="c1">#     crypto = Blowfish.new(self.db.passw, Blowfish.MODE_CBC, iv)</span>
        <span class="c1">#     self.auth=json.loads(crypto.decrypt(encr))</span>
        <span class="c1"># else:</span>
        <span class="c1">#     #just empty</span>
        <span class="c1">#     self.auth={}</span>
        <span class="c1">#     return</span>

<div class="viewcode-block" id="Settings.getDataDir"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.getDataDir">[docs]</a>    <span class="k">def</span> <span class="nf">getDataDir</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">scheme</span><span class="p">,</span><span class="n">dataset</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">subdirs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Retrieves the data Directory, possibly appended with a dataset and subdirs&quot;&quot;&quot;</span>
        <span class="c1">#begin with setting the default</span>
        <span class="n">ddir</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">getMirror</span><span class="p">(</span><span class="s2">&quot;default&quot;</span><span class="p">)</span>
        <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="n">scheme</span><span class="p">)</span>

        <span class="c1">#Possibly we need to append a dataset directory </span>
        <span class="k">if</span> <span class="n">dataset</span><span class="p">:</span>
            <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="n">dataset</span><span class="p">)</span>

        <span class="c1">#possibly append subdirectories</span>
        <span class="k">if</span> <span class="n">subdirs</span><span class="p">:</span>
            <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="n">subdirs</span><span class="p">)</span>

        <span class="c1">#NOTE: this posssibly applies a mapping of the root part of the directory </span>
        <span class="k">return</span> <span class="n">getCreateDir</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mirrorMap</span><span class="p">)</span></div>

<div class="viewcode-block" id="Settings.getCacheDir"><a class="viewcode-back" href="../../../reference/geoslurp.db.html#geoslurp.db.settings.Settings.getCacheDir">[docs]</a>    <span class="k">def</span> <span class="nf">getCacheDir</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">scheme</span><span class="p">,</span><span class="n">dataset</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">subdirs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Obtain and create a cache directory&quot;&quot;&quot;</span>
        <span class="c1">#starting point</span>
        <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">cache</span><span class="p">,</span><span class="n">scheme</span><span class="p">)</span>

        <span class="c1"># if &quot;CacheDir&quot; in self.userentry.conf:</span>
        <span class="c1">#     ddir=self.userentry.conf[&quot;CacheDir&quot;]</span>
        <span class="c1"># else:</span>
        <span class="c1">#     ddir=self.defaultentry.conf[&quot;CacheDir&quot;]</span>
        <span class="c1">#</span>
        <span class="c1"># ddir=os.path.join(ddir,scheme)</span>

        <span class="c1">#POssibly we need to append a dataset directory </span>
        <span class="k">if</span> <span class="n">dataset</span><span class="p">:</span>
            <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="n">dataset</span><span class="p">)</span>

        <span class="c1">#possibly append subdirectories</span>
        <span class="k">if</span> <span class="n">subdirs</span><span class="p">:</span>
            <span class="n">ddir</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ddir</span><span class="p">,</span><span class="n">subdirs</span><span class="p">)</span>

        <span class="c1">#NOTE: this posssibly applies a mapping of the root part of the directory </span>
        <span class="k">return</span> <span class="n">getCreateDir</span><span class="p">(</span><span class="n">ddir</span><span class="p">)</span></div></div>

</pre></div>

           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Roelof Rietbroek.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'v1.1.0',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>